<?php
$_ptime = microtime_float();
$_class_load = 0;

session_start();

require_once(".config");

function microtime_float()
{   
	list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

function pagetime() {
	global $_ptime;
	return round(1000*(microtime_float()-$_ptime));
}

function dbg($str) {
	global $DEBUG;
	if($DEBUG) {
		return $str;
	} else {
		return "Unexpected error, send to developer:<textarea rows=3 cols=40>".base64_encode($str)."</textarea>";
	}
}

/**
** Find class script in one of $CLS_PATH folders or in current
**/
function __autoload($class_name) {
	global $_class_load, $CLS_PATH, $CLS_PREFFIX, $CLS_SUFFIX;
	$clsload = microtime_float();
	$f = $_SERVER['DOCUMENT_ROOT'].substr($_SERVER['REQUEST_URI'],1).$CLS_PREFFIX.$class_name.$CLS_SUFFIX;
	if(file_exists($f)){
		require_once $f;
		$_class_load += (microtime_float() - $clsload);
		return;
	}
	foreach($CLS_PATH as $k => $v) {
		$f = $_SERVER['DOCUMENT_ROOT'].$v."/".$CLS_PREFFIX.$class_name.$CLS_SUFFIX;
		if(file_exists($f)){
			require_once $f;
			$_class_load += (microtime_float() - $clsload);
			return;
		}
	}

	die ("Can't load class \"".$class_name."\"");
}

?>